package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.MaintainRoom;
import com.xuetang9.t9.hotel.beans.RoomInfo;
import com.xuetang9.t9.hotel.mapper.condition.impl.MaintainRoomCondition;
import com.xuetang9.t9.hotel.mapper.condition.impl.RoomInfoCondition;
import com.xuetang9.t9.hotel.services.IMaintainRoomService;
import com.xuetang9.t9.hotel.utils.HttpCodeEnum;
import com.xuetang9.t9.hotel.utils.OverallConstant;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 维修房间controller
 */
@Controller
@RequestMapping("/maintain")
@ResponseBody
public class MaintainRoomController {

    @Autowired
    private IMaintainRoomService maintainRoomService;

    /**
     * 总览维修记录
     * @param condition
     * @return
     */
    @RequestMapping(value = "/maintain",method = RequestMethod.POST)
    private PageBean showMaintain(@RequestBody MaintainRoomCondition condition){
        if(condition == null){
            condition = new MaintainRoomCondition();
        }
        condition.setType(OverallConstant.ROOM_MAINTAIN_MAINTAION);
        return maintainRoomService.findByAll(condition);
    }

    /**
     * 总览清洁记录
     * @param condition
     * @return
     */
    @RequestMapping(value = "/show/clean",method = RequestMethod.POST)
    private PageBean showClone(@RequestBody MaintainRoomCondition condition){
        if(condition == null){
            condition = new MaintainRoomCondition();
        }
        condition.setType(OverallConstant.ROOM_MAINTAIN_CLEAN);
        return maintainRoomService.findByAll(condition);
    }

    /**
     * 保存记录
     * @param
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    private ResponseResult save(@RequestBody @Validated MaintainRoom maintainRoom){
        if(maintainRoom == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(maintainRoomService.save(maintainRoom)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 修改记录
     * @param
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    private ResponseResult update(@RequestBody MaintainRoom maintainRoom){
        if(maintainRoom == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(maintainRoomService.alter(maintainRoom)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 删除记录
     * @param
     * @return
     */
    @RequestMapping(value = "/remove/{id}")
    private ResponseResult save(@PathVariable("id") Integer id){
        if(id == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(maintainRoomService.remove(id)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

}
